import axios from 'axios';
const service = axios.create({
    baseURL: 'http://localhost:5251/',
    timeout: 5000,
});
service.interceptors.request.use(config => {
    return config;
}, err => {
    return Promise.reject(err);
});
service.interceptors.response.use(response => {
    if (response.status === 200 || response.status === 201) {
        return response;
    } else {
        ElMessage({
            message: '请求错误',
            type: 'error',
            plain: true,
        });
    }
}, err => {
    if (err.code == 'ERR_NETWORK') {
        console.log('err', err);
        ElMessage({
            message: '网络错误',
            type: 'error',
            plain: true,
        });
    } else if (err.status === 400) {
        ElMessage({
            message: err.response.data,
            type: 'error',
            plain: true,
        });
    } else if (err.status === 404) {
        ElMessage({
            message: err.response.data,
            type: 'warning',
            plain: true,
        });
    } else if (err.status === 500) {
        ElMessage({
            message: err.response.data,
            type: 'error',
            plain: true,
        });
    }
    return err.response;
});
export default service;